﻿package com.kaede.popcake;

import net.youmi.android.AdManager;
import net.youmi.android.diy.DiyManager;
import net.youmi.android.spot.SpotManager;
import android.content.Intent;
import android.media.MediaPlayer;
import android.os.Bundle;
import android.view.KeyEvent;
import android.view.View;
import android.widget.AdapterView;
import android.widget.AdapterView.OnItemClickListener;
import android.widget.GridView;

import com.actionbarsherlock.app.SherlockActivity;
import com.kaede.util.AppUitil;

public class MainActivity extends SherlockActivity implements OnItemClickListener{

	private MediaPlayer mMediaPlayer;
	@Override
	protected void onCreate(Bundle savedInstanceState) {
		super.onCreate(savedInstanceState);
		setContentView(R.layout.activity_main);
		GridView view = (GridView) findViewById(R.id.grid);
		view.setAdapter(new GridAdapter(getBaseContext()));
		view.setOnItemClickListener(this);
		load();
		AdManager.getInstance(this).init("7291f51ce48e4b4c","c2c864aeb51e55cc", false); 
		SpotManager.getInstance(this).loadSpotAds();
		DiyManager.initAdObjects(this);
	}

	com.actionbarsherlock.app.ActionBar action;

	public void load() {

		action = this.getSupportActionBar();
		action.setDisplayHomeAsUpEnabled(true);
		//action.setDisplayShowTitleEnabled(false);

	}
	
	
	@Override
	protected void onResume() {
		// TODO Auto-generated method stub
		super.onResume();
	}

	@Override
	protected void onDestroy() {
		// TODO Auto-generated method stub

		super.onDestroy();
	}

	@Override
	public boolean onCreateOptionsMenu(com.actionbarsherlock.view.Menu menu) {
		// TODO Auto-generated method stub
		getSupportMenuInflater().inflate(R.menu.main, menu);
		return super.onCreateOptionsMenu(menu);
	}

	@Override
	public boolean onOptionsItemSelected(
			com.actionbarsherlock.view.MenuItem item) {
		// TODO Auto-generated method stub
		switch (item.getItemId()) {
		case R.id.menu_full:
			if (AppUitil.changeScreen(this, action.isShowing()))
				action.hide();
			else
				action.show();
			break;
		case R.id.menu_nfull:
			if (AppUitil.changeScreen(this, action.isShowing()))
				action.hide();
			else
				action.show();
			break;
		case android.R.id.home:
			SpotManager.getInstance(this).showSpotAds(this);
			break;
		default:
			break;
		}
		return super.onOptionsItemSelected(item);
	}

	// 退出对话框回调方法
	public void more() {
		DiyManager.showRecommendWall(this);
	}

	@Override
	public boolean onKeyDown(int keyCode, KeyEvent event) {
		// TODO Auto-generated method stub
		AppUitil.confirmExit(keyCode, MainActivity.this);
		return super.onKeyDown(keyCode, event);
	}

	@Override
	public void onItemClick(AdapterView<?> arg0, View arg1, int arg2, long arg3) {
		// TODO Auto-generated method stub
	
		DataHolder.index=arg2;
		if (arg2!=7) {
			this.startActivity(new Intent().setClass(this, gifActivity.class));	
		}else	
		{
		AppUitil.MakeToastShort(this, "在线高清资源请更新最新版…");
		SpotManager.getInstance(this).showSpotAds(this);
		}
	}

}
